package cn.czu.wyw.config;

import cn.czu.wyw.intercept.MyPageHelp;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import tk.mybatis.spring.annotation.MapperScan;

import java.util.Properties;

/**
 * @Author wyw
 * @Description
 * @Date 2021/3/15 14:03
 * @Version 1.0
 */
@Configuration
//@MapperScan({"cn.czu.wyw.mapper"})
public class MyPageHelper {
    //将插件加入到mybatis插件拦截链中
//    @Bean
//    public ConfigurationCustomizer configurationCustomizer() {
//        return new ConfigurationCustomizer() {
//            @Override
//            public void customize(org.apache.ibatis.session.Configuration configuration) {
//                //插件拦截链采用了责任链模式，执行顺序和加入连接链的顺序有关
//                MyPageHelp myPageHelp = new MyPageHelp();
//                //设置参数，比如阈值等，可以在配置文件中配置，这里直接写死便于测试
//                Properties properties = new Properties();
//                //这里设置慢查询阈值为1毫秒，便于测试
//                properties.setProperty("time", "1");
//                properties.setProperty("userName", "wyw");
//                myPageHelp.setProperties(properties);
//                configuration.addInterceptor(myPageHelp);
//            }
//        };
//    }
    //注册插件
    @Bean
    @Primary
    public MyPageHelp myPageHelp() {
        MyPageHelp myPlugin = new MyPageHelp();
        //设置参数，比如阈值等，可以在配置文件中配置，这里直接写死便于测试
        Properties properties = new Properties();
        //这里设置慢查询阈值为1毫秒，便于测试
        properties.setProperty("time", "1");
        properties.setProperty("userName", "wyw");
        myPlugin.setProperties(properties);
        return myPlugin;
    }
}
